//
//  SJTabbarController.m
//  Recycling
//
//  Created by jzd on 2018/5/16.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "SJTabbarController.h"
#import "CurrentViewController.h"
#import "RegularViewController.h"
#import "AnnouncementVC.h"
#import "MessageViewController.h"
#import "PersonalViewController.h"
#import "SJNavgationController.h"

@interface SJTabbarController ()

@end

@implementation SJTabbarController
// 只会调用一次
+(void)initialize{
    if (self == [SJTabbarController class]) {
        // 获取哪个类中UITabBarItem
        UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
        // 设置按钮选中标题的颜色:富文本:描述一个文字颜色,字体,阴影,空心,图文混排
        // 创建一个描述文本属性的字典
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSForegroundColorAttributeName] = TITLECOLOR;
        [item setTitleTextAttributes:attrs forState:UIControlStateSelected];
//        attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
//        [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
        
        // 设置字体尺寸:只有设置正常状态下,才会有效果
        NSMutableDictionary *attrsNor = [NSMutableDictionary dictionary];
        attrsNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
        [item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    // 1 添加子控制器(5个子控制器) -> 自定义控制器 -> 划分项目文件结构
    [self setupAllChildViewController];
    
    // 2 设置tabBar上按钮内容 -> 由对应的子控制器的tabBarItem属性
    [self setupAllTitleButton];
    
    [self.tabBar setShadowImage:[[UIImage alloc]init]];

    
}
#pragma mark - 添加所有子控制器
- (void)setupAllChildViewController
{
    // 活期
    CurrentViewController *homeVc = [[CurrentViewController alloc] init];
    SJNavgationController *nav = [[SJNavgationController alloc] initWithRootViewController:homeVc];
    homeVc.extendedLayoutIncludesOpaqueBars = YES;
    [self addChildViewController:nav];
    
    // 定期
    RegularViewController *workOrderVc = [[RegularViewController alloc] init];
    SJNavgationController *nav1 = [[SJNavgationController alloc] initWithRootViewController:workOrderVc];
    workOrderVc.extendedLayoutIncludesOpaqueBars = YES;
    [self addChildViewController:nav1];
    
    

    // 公告
    AnnouncementVC *controlCenterVc = [[AnnouncementVC alloc] init];
    SJNavgationController *nav3 = [[SJNavgationController alloc] initWithRootViewController:controlCenterVc];
    controlCenterVc.extendedLayoutIncludesOpaqueBars = YES;
    [self addChildViewController:nav3];
    
    // 留言
    MessageViewController *mineVc = [[MessageViewController alloc] init];
    SJNavgationController *nav4 = [[SJNavgationController alloc] initWithRootViewController:mineVc];
    mineVc.extendedLayoutIncludesOpaqueBars = YES;
    [self addChildViewController:nav4];
    
    // 个人中心
    PersonalViewController *person = [[PersonalViewController alloc] init];
    SJNavgationController *nav5 = [[SJNavgationController alloc] initWithRootViewController:person];
    person.extendedLayoutIncludesOpaqueBars = YES;
    [self addChildViewController:nav5];
}

// 设置tabBar上所有按钮内容
- (void)setupAllTitleButton
{
    // 0:活期
    UINavigationController *nav = self.childViewControllers[0];
    nav.tabBarItem.title = @"活期";
    nav.tabBarItem.image = [UIImage imageOriginalWithName:@"current_Nomal"];
    // 快速生成一个没有渲染图片
    nav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"current_Select"];
    
    // 1:定期
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"定期";
    nav1.tabBarItem.image = [UIImage imageOriginalWithName:@"regular_Nomal"];
    nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"regular_Select"];
    
    // 3.公告
    UINavigationController *nav3 = self.childViewControllers[2];
    nav3.tabBarItem.title = @"公告";
    nav3.tabBarItem.image = [UIImage imageOriginalWithName:@"gonggao_Nomal"];
    nav3.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"gonggao_Select"];

   
    // 4.留言
    UINavigationController *nav4 = self.childViewControllers[3];
    nav4.tabBarItem.title = @"留言";
    nav4.tabBarItem.image = [UIImage imageOriginalWithName:@"message_Nomal"];
    nav4.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"message_Select"];
    
    // 4.个人中心
    UINavigationController *nav5 = self.childViewControllers[4];
    nav5.tabBarItem.title = @"个人中心";
    nav5.tabBarItem.image = [UIImage imageOriginalWithName:@"person_Nomal"];
    nav5.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"person_Select"];
}


@end
